home *** CD-ROM | disk | FTP | other *** search
- Path: news.magmacom.com!not-for-mail
- From: ezust@mag1.magmacom.com (Acme Instant Dehydrated Boulder Kit)
- Newsgroups: comp.lang.c++
- Subject: Re: C++ complex numbers slow as molasses?
- Date: 9 Apr 1996 13:04:24 -0400
- Organization: Cloud-Zero, Canada
- Message-ID: <4ke5ap$b8b@mag1.magmacom.com>
- References: <4k6k8c$8h4@nyx.cs.du.edu> <9604071851.AA001o1@lorelei.demon.co.uk>
- NNTP-Posting-Host: mag1.magmacom.com
-
- In article <9604071851.AA001o1@lorelei.demon.co.uk>,
- John Croudy <john@lorelei.demon.co.uk> wrote:
- >On 6 Apr 1996 13:30:04 -0700, A. N. Alias wrote:
- >
- >> bit slower, but I thought that the speed difference would
- >> be far less drastic (esp. if the C++ compiler inlines the
- >> arithmetic operators, as the Complex.h declarations specify).
- >
- >As far as I understand it, GNU only inlines if you have optimisations
- >turned up quite high. Like -O4 or something. Well, that's what I've
- >found from experience of Gnu C++ Version 2.7
- >
-
- Another problem you might be facing is, if you wrote in C your arithmetic
- operations as 3-argument functions passing pointers to structs for all 3
- arguments, then it would definitely be more efficient than using overloaded
- non-side-effeciting binary operators...
-
- I don't know how the gnu library is implemented, but it probalby works
- something like this:
-
- Complex a,b,c;
-
- a = b + c; // creates a temporary local in operator+,
- // returns that temporary local by value on the stack
- // performs an assignment
-
- But if you wrote a member function called
- add(const complex&a, const complex&b)
-
- which made "this" be the sum of a and b, you don't have any tempoaries being
- created... This can significantly speed up your code.
-
- non side-effecting binary operators usually are slower than writing regular
- (member) functions which take 3 (2) parameters by reference/pointer, placing
- the result into one of the parameters (or *this).
-
-
- --
- Alan Ezust "Just because I work for the federal
- Ottawa, Canada government doesn't mean I'm an expert
- ezust@magmacom.com on cockroaches" -Special Agent Fox Mulder
- http://www2.magmacom.com/~ezust
-